#include <gtest/gtest.h>
#include "common.h"
using namespace ::std;

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
		if(nullptr == head || nullptr == head->next) return head;
		ListNode* cursor = head;
		while(cursor->next != nullptr) {
			if(cursor->next->val == cursor->val) {
				cursor->next = cursor->next->next;
			} else {
				cursor = cursor->next;
			}
		}
		return head;
    }
};

class DeleteDuplicatesCheck : public ::testing::Test {
public:
	class Solution solution;
};

TEST_F(DeleteDuplicatesCheck, testDeleteDuplicates_1) {
	vector<int> vec = {};
	ListNode* head = makeVecToList(vec);
	EXPECT_TRUE(vector<int>({}) == (makeListToVec(solution.deleteDuplicates(head))));
}

TEST_F(DeleteDuplicatesCheck, testDeleteDuplicates_2) {
	vector<int> vec = {1,1,2};
	ListNode* head = makeVecToList(vec);
	EXPECT_TRUE(vector<int>({1,2}) == (makeListToVec(solution.deleteDuplicates(head))));
}

TEST_F(DeleteDuplicatesCheck, testDeleteDuplicates_3) {
	vector<int> vec = {1,1,2,3,3};
	ListNode* head = makeVecToList(vec);
	EXPECT_TRUE(vector<int>({1,2,3}) == (makeListToVec(solution.deleteDuplicates(head))));
}

TEST_F(DeleteDuplicatesCheck, testDeleteDuplicates_4) {
	vector<int> vec = {1};
	ListNode* head = makeVecToList(vec);
	EXPECT_TRUE(vector<int>({1}) == (makeListToVec(solution.deleteDuplicates(head))));
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}
